{
  LX Log module

  Based on modo's SDK lxlog.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software. Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012 David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Log;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result;

const
  LXa_LOGSERVICE            = 'logservice'  ;
  LXa_LOGINFOBLOCK          = 'loginfoblock';
  LXa_LOGENTRY              = 'logentry'    ;
  LXa_LOG                   = 'logsubsystem';

  LXfLOGEVENT_ENTRY         = $2000;
  LXfLOGEVENT_ROLLING       = $0100;
  LXfLOGEVENT_ADD           = $0010;
  LXfLOGEVENT_ADD_CHILD     = $0020;
  LXfLOGEVENT_DROP          = $0030;

  LXi_DBLOG_ERROR           = 1;
  LXi_DBLOG_NORMAL          = 2;
  LXi_DBLOG_TRACE           = 3;
  LXi_DBLOG_VERBOSE         = 4;

  LXiLOGCLASS_MESSAGE       = 0;
  LXiLOGCLASS_BLOCK         = 1;
  LXiLOGCLASS_PAIRS         = 2;

  LXiLOGEVENT_SUBSYSTEM_ADD = $1000;

  LXmLOGEVENT_CLASS         = $F000;
  LXmLOGEVENT_STYLE         = $0F00;
  LXmLOGEVENT_ACTION        = $00F0;

  LXsLOG_LOGSYS             = 'logsys'   ;
  LXsLOG_MASTERSYS          = 'master'   ;
  LXsLOG_PORTNAME           = 'logglobal';

  LXsSRV_LOGSUBSYSTEM       = 'server.logsubsystem';

  LXu_LOGSERVICE            = '{0BC355C2-5E6B-49EF-B368-600D9F26F543}';
  LXu_LOGINFOBLOCK          = '{B9AEE11A-3501-4dc2-90A6-41F2435856C6}';
  LXu_LOGENTRY              = '{E83679B2-DB4D-4D90-B81B-5F786D212FB3}';
  LXu_LOG                   = '{1890538F-D64C-478c-8472-228B7C9AB1DF}';

type
  ILxLogService = interface
  [LXu_LOGSERVICE]
    function ScriptQuery                 (  out VObj                 ) : LxResult;
    function SubSystemCount              (      Count      : PUInt32 ) : LxResult;
    function SubSystemByIndex            (      Index      : UInt32  ;
                                            out VObj                 ) : LxResult;
    function SubSystemLookup             (const Name       : PChar   ;
                                            out VObj                 ) : LxResult;
    function MasterSubSystem             (  out VObj                 ) : LxResult;
    function InfoBlockCount              (      Count      : PUInt32 ) : LxResult;
    function InfoBlockByIndex            (      Index      : UInt32  ;
                                            out VObj                 ) : LxResult;
    function InfoBlockLookup             (const Name       : PChar   ;
                                            out VObj                 ) : LxResult;
    function InfoBlockFieldsAreSameGroup (const Name1      : PChar   ;
                                          const Name2      : PChar   ) : LxResult;
    function InfoBlockFieldGetParts      (const Name       : PChar   ;
                                          const Group      : PPChar  ;
                                          const Sub        : PPChar  ) : LxResult;
    function CreateEntryMessage          (      &Type      : LxResult;
                                          const Message    : PChar   ;
                                            out VObj                 ) : LxResult;
    function CreateEntryInfoBlock        (      &Type      : LxResult;
                                          const BlockName  : PChar   ;
                                            out VObj                 ) : LxResult;
    function CreateEntryPaired           (      &Type      : LxResult;
                                            out VObj                 ) : LxResult;
    function SetMonitor                  (      Monitor    : IUnknown) : LxResult;
    function AcquireMonitor                                            : IUnknown;
    function EnableLogging               (const SystemName : PChar;
                                                State      : UInt32  ) : LxResult;
    function IsLoggingEnabled            (const SystemName : PChar   ) : LxResult;
    function CreateEntryMessageFromMsgObj(      MsgObj     : IUnknown;
                                            out VObj                 ) : LxResult;
    function DebugLogOutput              (      Level      : UInt32  ;
                                          const Line       : PChar   ) : LxResult;
    function DebugLogOutputSys           (      Level      : UInt32  ;
                                          const LogSystem  : PChar   ;
                                          const Line       : PChar   ) : LxResult;
  end;

  ILxLogInfoBlock = interface
  [LXu_LOGINFOBLOCK]
    function Name      (const Name  : PPChar ) : LxResult;
    function FieldCount(      Count : PUInt32) : LxResult;
    function FieldName (      Index : UInt32 ;
                        const Name_ : PPChar ) : LxResult;
    function FieldType (      Index : UInt32 ;
                        const &Type : PPChar ) : LxResult;
  end;

  ILxLogEntry = interface
  [LXu_LOGENTRY]
    function AddEntry        (      Entry     : IUnknown ) : LxResult   ;
    function SetTitle        (const Title     : PChar    ) : LxResult   ;
    function SetDesc         (const Desc      : PChar    ) : LxResult   ;
    function SetValue        (const Name      : PChar    ;
                                    Index     : UInt32   ;
                                    Value     : IUnknown ) : LxResult   ;
    function AddPair         (const Name      : PChar    ;
                              const Value     : PChar    ) : LxResult   ;
    function &Class          (      ClassType : UInt32   ) : LxResult   ;
    function &Type           (      &Type     : PLxResult) : LxResult   ;
    { XXX : Convert time_t to TDateTime with UnixToDateTime function for usage }
    function Time            (      Time      : Int64    ) : LxResult   ;
    function TimeString      (const &String   : PPChar   ) : LxResult   ;
    function ChildCount      (      Count     : PUInt32  ) : LxResult   ;
    function ChildByIndex    (      Index     : UInt32   ;
                                out VObj                 ) : LxResult   ;
    function PeekChildByIndex(      Index     : UInt32   ) : ILxLogEntry;
    function SubSystemCount  (      Count     : PUInt32  ) : LxResult   ;
    function SubSystemByIndex(      Index     : UInt32   ;
                                out VObj                 ) : LxResult   ;
    function Message         (const Message   : PPChar   ) : LxResult   ;
    function Title           (const Title     : PPChar   ) : LxResult   ;
    function Desc            (const Desc      : PPChar   ) : LxResult   ;
    function InfoBlock       (  out VObj                 ) : LxResult   ;
    function InfoBlockValue  (      Index     : UInt32   ;
                                out VObj                 ) : LxResult   ;
    function PairCount       (      Count     : PUInt32  ) : LxResult   ;
    function PairName        (      Index     : UInt32   ;
                              const Name      : PPChar   ) : LxResult   ;
    function PairValue       (      Index     : UInt32   ;
                              const Value     : PPChar   ) : LxResult   ;
  end;

  ILxLog = interface
  [LXu_LOG]
    function AddEntry        (      Entry : IUnknown) : LxResult   ;
    function RollEntry       (      Entry : IUnknown) : LxResult   ;
    function RollClear                                : LxResult   ;
    function EntryCount      (      Count : PUInt32 ) : LxResult   ;
    function EntryByIndex    (      Index : UInt32  ;
                                out VObj            ) : LxResult   ;
    function PeekEntryByIndex(      Index : UInt32  ) : ILxLogEntry;
    function GetCurrentEntry (  out VObj            ) : LxResult   ;
    function SetMaxEntries   (      Max   : UInt32  ) : LxResult   ;
    function GetMaxEntries   (      Max   : PUInt32 ) : LxResult   ;
    function GetRolling      (  out VObj            ) : LxResult   ;
    function ClearAll                                 : LxResult   ;
    function Name            (const Name  : PPChar  ) : LxResult   ;
  end;

  PLXtLogEntryEvent = ^LXtLogEntryEvent;
  LXtLogEntryEvent  = record
    System : ILxLog;
    Entry  : ILxLogEntry;
  end;

  PLXtLogEntryChildEvent = ^LXtLogEntryChildEvent;
  LXtLogEntryChildEvent  = record
    Parent : ILxLogEntry;
    Entry  : ILxLogEntry;
  end;

function LXe_LOG_DEBUG : LxResult;

implementation

function LXe_LOG_DEBUG : LxResult; inline;
begin
  Result := LXxGOODCODE(LXeSYS_LOG, 1);
end;

end.

